package com.example.springbootproject.controller;/*
 *@author 王志威
 *@datatime 2024/4/16 13:07
 *@editnote
 */

import com.example.springbootproject.pojo.Admin;
import com.example.springbootproject.service.RegisterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.security.NoSuchAlgorithmException;

@Slf4j
@Controller
@RequestMapping("/user")
//@Validated
public class RegisterController {
    @Autowired
    private RegisterService registerService;

    //注册页面
    @RequestMapping("/registerMain")
    public String registerMain() {
        return "ZhuCePage";
    }

    //注册,前端参数要有账号、密码、确认密码
    @PostMapping("/register")
    public String register(@Valid @RequestBody  Admin admin) throws NoSuchAlgorithmException {
            registerService.register(admin.getUserName(), admin.getEncryptedPassword());
            return "redirect:loginMain";
    }
}
